package de.tuhh.simsearch.model.persistence.contentmgmt.eao.interfaces;

import java.math.BigInteger;
import java.util.List;

import javax.ejb.Local;

import de.tuhh.simsearch.model.persistence.contentmgmt.entities.CategoryEntity;
import de.tuhh.simsearch.model.persistence.contentmgmt.entities.FileEntity;

/**
 * This is the interface between the database access bean in the content manager and the content controller. It describes the
 * functions needed in the controller. The access object should implement this interface.
 * 
 * @author SimSearch 1
 * 
 */
@Local
public interface ContentMgmtEAOInterface {

  /**
   * Gets the file entity object of a file with a given id
   * @param id the id of the file
   * @return the entity object for the file
   */
  public FileEntity getFileEntity(BigInteger id);

  /**
   * Adds a new file entity to the database
   * 
   * @param entity
   *          the file entity to persist
   * @return true if operation was successful
   */
  public boolean addFileEntity(FileEntity entity);

  /**
   * Remove a file entity from the database
   * 
   * @param id
   *          the id of the file to remove
   * @return true if operation was successful
   */
  public boolean removeFileEntity(BigInteger id);

  /**
   * Search files by name
   * 
   * @param srchStrg
   *          the string to search for within file names
   * @return the list of files which names contain the search string
   */
  public List<FileEntity> searchFiles(String srchStrg);

  /**
   * Searches for all files which are associated with one of the categories from a category list.
   * 
   * @param categories
   *          the list of categories to search for
   * @return the resulting list of files
   */
  public List<FileEntity> searchFiles(List<CategoryEntity> categories);

  /**
   * Checks if a filename is already used
   * 
   * @param filename
   *          the file name to check
   * @param path
   *          the path where the file should be created
   * @return true if successful, false otherwise
   */
  public boolean isFileNameFree(String filename, String path);

  /**
   * Gets a category entity
   * 
   * @param categoryName
   *          the category name
   * @param contentID
   *          the content type of the category
   * @return the category entity
   */
  public CategoryEntity getCategoryEntity(String categoryName, Integer contentID);

  /**
   * Removes a category from a file
   * 
   * @param categoryName
   *          the name of the category to remove
   * @param contentID
   *          the content type
   * @param file
   *          the file where the category should be removed
   * @return true if successful, false otherwise
   */
  public boolean removeCategoryEntity(String categoryName, Integer contentID, FileEntity file);

  /**
   * Adds a category entity to the database. Should only be possible for the content administrator.
   * 
   * @param entity
   *          the category entity to persist
   * @return true if operation was successful
   */
  public boolean addCategoryEntity(CategoryEntity entity);

  /**
   * Searches within the category names for a string
   * 
   * @param srchStrg
   *          the string to search for
   * @return the resulting list of categories
   */
  public List<CategoryEntity> searchCategories(String srchStrg);

  /**
   * Removes a category entity from the database. Should only be possible for the content administrator.
   * 
   * @param categoryName
   *          the name of the category
   * @param contentID
   *          the content type of the category
   * @return true if operation was successful
   */
  public boolean removeCategoryEntity(String categoryName, Integer contentID);

  /**
   * Updates a category entity. Assigns a new name and a new content type to a category entity already in the database.
   * Should only be executed by a content administrator.
   * 
   * @param oldName
   *          the old category name
   * @param oldContentID
   *          the old content type
   * @param newName
   *          the new category name
   * @param newContentID
   *          the new content type
   * @return true if operation was successful
   */
  public boolean updateCategoryEntity(String oldName, Integer oldContentID, String newName, Integer newContentID);

  /**
   * Searches within the file descriptions.
   * 
   * @param srchstrg
   *          the string to search for
   * @return the resulting list of file entities
   */
  public List<FileEntity> searchFilesByDesc(String srchstrg);

}
